/*
ActionScript Extension for FlashSound Javascript API
copyright 2001 Hayden Porter, hayden@aviarts.com
v 1.0.1 last update June 6, 2001
*/

// required for compatibility with Netscape3
new FlashSound()

// determine if string represents a valid
// floating point, ingeter or negatvie number
function convertObjtoPrimative(str)
{
	var dpcount = 0; // decimal point count
	var validNum = true; 
	for (var i=0; i<=str.length - 1; i++)
	{
		var character = str.charAt(i);
		// look for decimal point or integers
		var validChar = (character == "." || parseInt(character) >= 0) ? true : false;
		// look for negative sign as first character
		if(i == 0 && character == "-") {validChar = true}
		if(character == ".") {dpcount = dpcount + 1;}
		// if character is not an integer or more than one decimal point 
		// string is not a valid number
		if(!validChar || dpcount > 1) {validNum = false; break; }
	}
	if (validNum && dpcount == 1) { return parseFloat(str); }
	else if (validNum) { return parseInt(str); }
	else {return str}
}

function Flash_api_GetVariable(variableName)
{
	if(!this.isPlayerReady()) return null;
	var objValue = String(window.document[this.playerID].GetVariable(variableName));
	//check if a number then convert to number
	var retValue = convertObjtoPrimative(objValue);
	return retValue;	
}

function Flash_api_SetVariable(variableName,value)
{
	if(!this.isPlayerReady()) return;
	window.document[this.playerID].SetVariable(variableName,value);
}

var _currentframe = 4; //number read only
var _framesloaded = 12; //number read only
var _name = 13; // string read/write
var _soundbuftime = 18; //number read/write global property
var _target = 11; // string read only
var _totalframes = 5; //number read only
var _url = 15; //string read only

function Flash_api_TGetProperty(target,propertyName)
{
	if(!this.isPlayerReady()) {return null;}
	var ojbValue =  String(window.document[this.playerID].TGetProperty(target,propertyName));
	//check if a number then convert to number
	var retValue = convertObjtoPrimative(objValue);
	return retValue;
}

function Flash_api_TSetProperty(target,propertyName,value)
{
	if(!this.isPlayerReady()) {return;}
	window.document[this.playerID].TSetProperty(target,propertyName,value)
}

function Flash_TCall(target,frame)
{
	if(!this.isPlayerReady()) {return}
	if(typeof(frame) == "number")
	{
		window.document[this.playerID].TCallFrame(target,frame - 1);
	}
	if(typeof(frame) == "string")
	{
		window.document[this.playerID].TCallLabel(target,frame);
	}
}

function FlashSound_evalFSCommand(command,args)
{
	// if comamnd contains complete function string ignore args
	// otherwise build a function call with open and closed parenthesis
	if(command.indexOf('(') != -1 && command.indexOf(')') != -1)
	{
		var commandstr = String(command);
	}
	else
	{
		var args = convertObjtoPrimative(args);
		var args = (typeof(args) == "string") ? '\"' + args + '\"' : args;
		var commandstr = command + '(' + args + ')';
	}
	// eval function call
	eval(commandstr);
}

function FlashSound_handleFSCommands(state)
{
	if(state == null) state = true;
	if(!state) return;
	window[this.playerID + '_DoFSCommand'] = FlashSound_evalFSCommand;
	if(FlashSound.winIEpass)
	{
		document.writeln(
		'<SCRIPT LANGUAGE="VBScript">'+
		'Sub ' + this.playerID + '_FSCommand (ByVal command, ByVal args)'+
		'call FlashSound_evalFSCommand (command, args)'+
		'end sub'+
		'</SCRIPT>'
		);
	}
}

FlashSound.prototype.GetVariable = Flash_api_GetVariable;
FlashSound.prototype.handleFSCommands = FlashSound_handleFSCommands;
FlashSound.prototype.SetVariable = Flash_api_SetVariable;
FlashSound.prototype.TCall = Flash_TCall;
FlashSound.prototype.TGetProperty = Flash_api_TGetProperty;
FlashSound.prototype.TSetProperty = Flash_api_TSetProperty;